/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-11-19
 * Time: 23:06
 */
public class Test {
    public static void main(String[] args) {
        int a = 7;
        int n = 560;
        int m = 561;
        int[] b = new int[]{0,0,0,0,1,1,0,0,0,1};
        int c = 1;
        for(int i = b.length-1; i >= 0; i--) {
            c = (c*c) % m;
            if(b[i] == 1) {
                c = (a*c) % m;
            }
        }
        System.out.println(c);
    }
}
